package org.hu.controller;

import org.hu.model.MeetingRoom;
import org.hu.service.MeetingRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 会议室
 * @author Htrees
 */
@Controller
public class MeetingRoomController {

    @Autowired
    MeetingRoomService meetingRoomService;

    /**
     * 会议室页面
     * @param model
     * @return meetingrooms
     */
    @RequestMapping("/meetingrooms")
    public String meetingrooms(Model model){
        model.addAttribute("mrs",meetingRoomService.getAllMr());
        return "meetingrooms";
    }

    /**
     * 会议室详情
     * @param id 会议室编号
     * @param model
     * @return roomdetails
     */
    @RequestMapping("/roomdetails")
    public String roomdetails(Integer id,Model model)
    {
        model.addAttribute("mr",meetingRoomService.getMrDetail(id));
        return "roomdetails";
    }

    /**
     * 更新会议室详情
     * @param meetingRoom 会议室对象
     * @return meetingrooms
     */
    @RequestMapping("/updateRoomDetail")
    public String updateRoomDetail(MeetingRoom meetingRoom){
        Integer result = meetingRoomService.updateRoomDetail(meetingRoom);
        if(result==0){
            return "forward:/roomdetails";
        }else{
            return "redirect:/meetingrooms";
        }
    }

    /**
     * 添加会议室页面
     * @return addmeetingroom
     */
    @RequestMapping("/admin/addMeetingRoom")
    public String addMeetingRoom(){
        return "addmeetingroom";
    }

    /**
     * 添加会议室
     * @param meetingRoom
     * @return
     */
    @RequestMapping("/admin/doAddMr")
    public String doAddMr(MeetingRoom meetingRoom){
        meetingRoomService.doAddMr(meetingRoom);
        return "redirect:/meetingrooms";
    }
}
